import Vue from 'vue';
import Vuex from 'vuex';
import axios from 'axios';
Vue.use(Vuex);

var store = new Vuex.Store({
    state: {
       lunbo:[],
       none:[],
       cat:[],
       pet:[],
       fesh:[],
       tuijian:[],
       kill:[],
       isLogin:false,
       typeclass:[],
       dog:[],
       doglist:[],
       catlist:[],
       home:[],
       b:""
    },
    getters: {

    },
    mutations:{
         setlunbo:function(state,value){
            state.lunbo = value;
        },
         setnone:function(state,value){
            state.none = value;
        },
        setcat:function(state,value){
            state.cat = value;
        },
        setpet:function(state,value){
            state.pet = value;
        },
        setfesh:function(state,value){
            state.fesh = value;
        },
        settuijian:function(state,value){
            state.tuijian = value;
        },
        setkill:function(state,value){
            state.kill = value;
        },
        setisLogin:function(state,value){
            state.isLogin = value;
        },
        settypeclass:function(state,value){
            state.typeclass = value;
        },
         setdog:function(state,value){
            state.dog = value;
        },
         setdoglist:function(state,value){
            state.doglist = value;
        },
         setcatlist:function(state,value){
            state.catlist = value;
        },
         setcatlist2:function(state,value){
            state.catlist = value;
        },
         setcatlist4:function(state,value){
            state.catlist = state.catlist.concat(value);
        },
         setcatlist3:function(state,value){
            state.catlist = value;
        },
         sethome:function(state,value){
            state.home = value;
        },
        sethome2:function(state,value){
            state.home = value;
        },
        settwodetail:function(state,value){
            state.catlist = value;
        },
        settwodetail2:function(state,value){
            state.catlist = value;
        }

    },
    actions:{
        // 首页请求
        requestlunbo:function(context,data){
             axios.get("/api/swiper")
        .then(res=>{
           context.commit("setlunbo",res.data.msg);
        })
        },
         requestnone:function(context,data){
             axios.get("/api/none")
        .then(res=>{
           context.commit("setnone",res.data.msg);
        })
        },
     requestcat:function(context,data){
             axios.get("/api/cat")
        .then(res=>{
           context.commit("setcat",res.data.msg);
        })
        },
     requestpet:function(context,data){
             axios.get("/api/pet")
        .then(res=>{
           context.commit("setpet",res.data.msg);
        })
        },
     requestfesh:function(context,data){
             axios.get("/api/fesh")
        .then(res=>{
           context.commit("setfesh",res.data.msg);
        })
        },
     requesttuijian:function(context,data){
             axios.get("/api/tuijian")
        .then(res=>{
           context.commit("settuijian",res.data.msg);
        })
        },
     requestkill:function(context,data){
             axios.get("/api/kill")
        .then(res=>{
           context.commit("setkill",res.data.msg);
        })
        },
    requestisLogin:function(context,data){
        axios.get("/api/users/isLogin")
        .then(res=>{
            // console.log(res.data.isLogin.isLogin)
            context.commit("setisLogin",res.data.isLogin.isLogin);
            
        })
    },
     requesttypeclass:function(context,data){
        axios.get("/api/typeclass")
        .then(res=>{
            // console.log(res.data.data)
            context.commit("settypeclass",res.data.data);
            
        })
    },
     requestdog:function(context,param){
            return new Promise(function(resolve,reject){
                axios.post("/api/dog",param).then(res=>{ 
                    resolve(res);
                    // console.log(res.data.data) 
                    context.commit("setdog",res.data.data);
                })
            })
        },
        requestdoglist:function(context,param){
            return new Promise(function(resolve,reject){
                axios.post("/api/doglist",param).then(res=>{ 
                    resolve(res);
                    // console.log(res.data.data) 
                    context.commit("setdoglist",res.data.data);
                })
            })
        },
         requestcatlist:function(context,param){
            return new Promise(function(resolve,reject){
                axios.post("/api/catlist",param).then(res=>{ 
                    resolve(res);
                    // console.log(res.data.data) 
                    context.commit("setcatlist",res.data.data);
                })
            })
        },
         requestcatlist2:function(context,param){
            return new Promise(function(resolve,reject){
                axios.post("/api/catlist2",param).then(res=>{ 
                    resolve(res);
                    // console.log(res.data.data) 
                    context.commit("setcatlist2",res.data.data);
                })
            })
        },
         requestcatlist3:function(context,param){
            return new Promise(function(resolve,reject){
                axios.post("/api/catlist3",param).then(res=>{ 
                    resolve(res);
                    // console.log(res.data.data) 
                    context.commit("setcatlist3",res.data.data);
                })
            })
        },
         requestcatlist4:function(context,param){
            return new Promise(function(resolve,reject){
                axios.post("/api/catlist4",param).then(res=>{ 
                    resolve(res);
                    // console.log(res.data.data) 
                    context.commit("setcatlist4",res.data.data);
                })
            })
        },
        requesthome:function(context,param){
            return new Promise(function(resolve,reject){
                axios.post("/api/home",param).then(res=>{ 
                    resolve(res);
                    // console.log(res.data.data) 
                    context.commit("sethome",res.data.data);
                })
            })
        },
        requesthome2:function(context,param){
            return new Promise(function(resolve,reject){
                axios.post("/api/home2",param).then(res=>{ 
                    resolve(res);
                    // console.log(res.data.data) 
                    context.commit("sethome2",res.data.data);
                })
            })
        },
         requesttwodetail:function(context,param){
            return new Promise(function(resolve,reject){
                axios.post("/api/twodetail",param).then(res=>{ 
                    resolve(res);
                    console.log(res.data.data) 
                    context.commit("settwodetail",res.data.data);
                })
            })
        },
         requesttwodetail2:function(context,param){
            return new Promise(function(resolve,reject){
                axios.post("/api/twodetail2",param).then(res=>{ 
                    resolve(res);
                    console.log(res.data.data) 
                    context.commit("settwodetail2",res.data.data);
                })
            })
        },
         bbb:function(context,param){
            this.state.b = param;
        },
        
    }
})

export default store;